package org.anderground.internal.graphics.impl;

import org.anderground.internal.graphics.abstaractions.AbstractLinearGradient;

import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.graphics.Shader.TileMode;

public class AndroidLinearGradient extends AndroidShader implements
		AbstractLinearGradient {

	private float x0, y0, x1, y1;
	private int color0, color1;
	private boolean simple;
	private int[] colors;
	private float[] positions;

	public AndroidLinearGradient(float x0, float y0, float x1, float y1,
			int color0, int color1) {
		super();
		this.x0 = x0;
		this.y0 = y0;
		this.x1 = x1;
		this.y1 = y1;
		this.color0 = color0;
		this.color1 = color1;
		this.simple = true;
	}

	public AndroidLinearGradient(float x0, float y0, float x1, float y1,
			int[] colors, float[] positions) {
		super();
		this.x0 = x0;
		this.y0 = y0;
		this.x1 = x1;
		this.y1 = y1;
		this.colors = colors;
		this.positions = positions;
		this.simple = false;
	}

	@Override
	public Shader getShader() {
		if (simple) {
			return new LinearGradient(x0, y0, x1, y1, color0, color1,
					TileMode.CLAMP);
		} else {
			return new LinearGradient(x0, y0, x1, y1, colors, positions,
					TileMode.CLAMP);
		}
	}

}
